// pages/new_inter/zhifu/zhifu.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    if (options.type == "预约成功") {

      var act= "kanfang_GetUnifiedOrderResult";
      var url = "../../personal/yuyue/yuyue"

    } else if (options.type == "报备成功") {
      var act = "baobei_GetUnifiedOrderResult";
      var url = "../../personal/baobei/baobei"

    } else if (options.type == "购买商品"){
      var act="GetUnifiedOrderResult";
      var url ="../../personal/dingdan/dingdan"
    }else{
      var act = "lvju_GetUnifiedOrderResult";
      var url = "../../personal/lvjuka/lvjuka"
    }
    this.setData({
      id: options.orderid,
      type: options.type,
      act: act,
      url: url
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  formSubmit: function (e) {
    console.log(e)

    var that = this;
    var formData = e.detail.value;
    formData['id'] = that.data.id;
    formData['userId'] = wx.getStorageSync('userId');

    // if (formData['Code'] == "" || formData['PassWord_2'] == "") {
    //   wx.showToast({
    //     title: '必填',
    //     icon: 'none'
    //   })
    //   return;
    // }
    // that.setData({
    //   button: 'false'
    // })
    // console.log(that.data.button)
    // return ;
    wx.request({
      url: app.globalData.apiUrl + 'Pay/'+that.data.act,
      data: formData,
      header: {
        'Content-Type': 'application/json'
      },
      method: 'POST',
      success: function (res) {
        if (res.data.status == 1) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            success: function () {
              setTimeout(function () {
                wx.redirectTo({
                  url: that.data.url,
                })
              }, 2000);
            }
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
        // that.setData({
        //   button: 'true'
        // })
      }
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  
  /**
   * 用户点击右上角分享
   */
  //onShareAppMessage: function () {

  //},
  zhifupass:function(){
    wx.navigateTo({
      url: '/pages/personal/security/zhifupass/zhifupass',
    })
  }
})